package com.fenghongzhang.kuaishou.mvp.register.view;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.fenghongzhang.kuaishou.MainActivity;
import com.fenghongzhang.kuaishou.R;
import com.fenghongzhang.kuaishou.mvp.login.entity.UserInfoBean;
import com.fenghongzhang.kuaishou.mvp.register.contract.RegisterContract;
import com.fenghongzhang.kuaishou.mvp.register.model.RegisterModel;
import com.fenghongzhang.kuaishou.mvp.register.presenter.RegisterPresenter;
import com.fenghongzhang.kuaishou.utils.SPUtil;
import com.fenghongzhang.mvp_lib.view.BaseActivity;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

import static com.umeng.message.proguard.m.a;
import static com.umeng.message.proguard.m.c;
import static com.umeng.message.proguard.m.d;
import static com.umeng.message.proguard.m.t;


public class RegisterActivity extends BaseActivity<RegisterPresenter> implements RegisterContract.IRegisterView {

    private static final String TAG = "RegisterActivity";

    @BindView(R.id.name)
    EditText name;
    @BindView(R.id.pwd)
    EditText pwd;
    @BindView(R.id.login)
    Button login;

    @Override
    public int bindLayout() {
        return R.layout.activity_register;
    }

    @Override
    public void initView() {
        ButterKnife.bind(this);
    }

    @Override
    public void initData() {
        mPresenter = new RegisterPresenter(new RegisterModel(),this);
    }


    @Override
    public void showToast(String msg) {

    }

    @Override
    public String getName() {
        return name.getText().toString();
    }

    @Override
    public String getPwd() {
        return pwd.getText().toString();
    }

    @Override
    public void isRegisterOk(UserInfoBean registerInfoBean) {
        Log.i(TAG, "isRegisterOk: ");
        UserInfoBean.DataBean data = registerInfoBean.getData();
        Toast.makeText(this, data.getUserName()+":注册成功~", Toast.LENGTH_SHORT).show();
        UserInfoBean.DataBean result = registerInfoBean.getData();
        SPUtil.getInstance().putString("userName",result.getUserName());
        MainActivity.launch(this);
    }


    @OnClick(R.id.login)
    public void onViewClicked() {
        mPresenter.register();
    }

    /**
     * 登录成功的逻辑
     * 在sp存入登录的用户
     * 然后跳转到主页面中
     * 并且把登录的文字换成图标
     */

    public static void launch(Activity activity){
        Intent intent = new Intent(activity,RegisterActivity.class);
        activity.startActivity(intent);
    }

}
